﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports DevComponents.DotNetBar.Controls
Imports DevComponents.Editors.DateTimeAdv
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DTO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.BUSS

Namespace DoAnQuanLyBanHang.DAO
    Public Class NhanVienCtrl
        Private m_NhanVienData As New NhanVienData()
        Private m_NhanVienInfo As New NhanVienInfo()
        Public Sub HienThiComboBox(cbx As ComboBox)
            Dim m_DT As DataTable = m_NhanVienData.LayNhanVien()
            cbx.DataSource = m_DT
            cbx.DisplayMember = "HoTenNV"

            cbx.ValueMember = "MaNV"


        End Sub

        Public Shared Function LayDsNhanVien() As IList(Of NhanVienInfo)
            Dim ds As IList(Of NhanVienInfo) = New List(Of NhanVienInfo)()

            Dim data As New NhanVienData()
            Dim tbl As DataTable = data.LayDSNhanVien()

            Dim NhanVien As IList(Of NhanVienInfo) = New List(Of NhanVienInfo)()

            For Each row As DataRow In tbl.Rows
                Dim NV As New NhanVienInfo()

                Dim m_QGD As New QuayGiaoDichInfo()
                m_QGD.TenQuayGD = Convert.ToString(row("TenQuayGiaoDich"))

                NV.MaNV = Convert.ToString(row("MaNV"))
                NV.HoTen = Convert.ToString(row("HoTenNV"))
                NV.DiaChi = Convert.ToString(row("DiaChi"))
                NV.DienThoai = Convert.ToString(row("DienThoai"))
                NV.NgaySinh = Convert.ToDateTime(row("NgaySinh"))

                NV.MaQuayGD = m_QGD

                NhanVien.Add(NV)
            Next
            Return NhanVien
        End Function

#Region "Hien thi ComboBox trong DataGridView"
        Public Sub HienThiDataGridViewComboBoxColumn(cmbColumn As DataGridViewComboBoxColumn)
            cmbColumn.DataSource = m_NhanVienData.LayNhanVien()
            cmbColumn.DisplayMember = "HoTenNV"
            cmbColumn.ValueMember = "MaNV"
            cmbColumn.DataPropertyName = "MaNV"
            cmbColumn.HeaderText = "Tên nhân viên"
        End Sub
#End Region

#Region "hien thi"
        Public Sub HienThi(Dgv As DataGridView, bvn As BindingNavigator)
            Dim bs As New BindingSource()

            bs.DataSource = m_NhanVienData.LayNhanVien()
            bvn.BindingSource = bs
            Dgv.DataSource = bs
        End Sub

        Public Sub HienThi(dGV As DataGridViewX, bN As BindingNavigator, txtMaNV As TextBoxX, txtHoTen As TextBoxX, dtNgaySinh As DateTimeInput, txtDiaChi As TextBoxX, _
         txtSoDienThoai As TextBoxX, cmbQuayGiaoDich As ComboBoxEx)
            Dim bS As New BindingSource()
            bS.DataSource = m_NhanVienData.LayNhanVien()

            txtMaNV.DataBindings.Clear()
            txtMaNV.DataBindings.Add("Text", bS, "MaNV")

            txtHoTen.DataBindings.Clear()
            txtHoTen.DataBindings.Add("Text", bS, "HoTenNV")

            txtSoDienThoai.DataBindings.Clear()
            txtSoDienThoai.DataBindings.Add("Text", bS, "DienThoai")

            dtNgaySinh.DataBindings.Clear()
            dtNgaySinh.DataBindings.Add("Value", bS, "NgaySinh")

            txtDiaChi.DataBindings.Clear()
            txtDiaChi.DataBindings.Add("Text", bS, "DiaChi")

            cmbQuayGiaoDich.DataBindings.Clear()
            cmbQuayGiaoDich.DataBindings.Add("SelectedValue", bS, "MaQuayGiaoDich")


            bN.BindingSource = bS
            dGV.DataSource = bS
        End Sub
#End Region

#Region "Them moi"
        Public Function ThemDongMoi() As DataRow
            Return m_NhanVienData.ThemDongMoi()
        End Function
        Public Sub ThemMoi(m_Row As DataRow)
            m_NhanVienData.ThemNhanVien(m_Row)
        End Sub
#End Region

#Region "Luu"
        Public Function LuuNhanVien() As Boolean
            Return m_NhanVienData.LuuNhanVien()
        End Function

        Public Sub LuuNhanVien(manv As [String], hoten As [String], ngaysinh As DateTime, diachi As [String], dienthoai As [String], maquaygd As [String])
            m_NhanVienData.LuuNhanVien(manv, hoten, ngaysinh, diachi, dienthoai, maquaygd)
        End Sub
#End Region

#Region "Sửa"
        Public Sub SuaNhanVien(manv As [String], hoten As [String], ngaysinh As DateTime, diachi As [String], dienthoai As [String], maquaygd As [String])
            m_NhanVienData.SuaNhanVien(manv, hoten, ngaysinh, diachi, dienthoai, maquaygd)
        End Sub
#End Region

#Region "Xóa"
        Public Sub XoaNhanVien(manv As [String])
            m_NhanVienData.XoaNhanVien(manv)
        End Sub
#End Region
#Region "tim kiem"
        Public Sub TimKiemTheoMa(m_MaNV As [String])
            m_NhanVienData.TimKiemTheoMa(m_MaNV)
        End Sub

        Public Sub TiemKiemTheoTen(m_HoTen As [String])
            m_NhanVienData.TimKiemTheoTen(m_HoTen)
        End Sub
#End Region

    End Class
End Namespace